package test.file;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class MergeFiles {

	String filepath1;
	String filepath2;

	public MergeFiles(String fp1, String fp2) {
		this.filepath1 = fp1;
		this.filepath1 = fp2;
	}

	public void mergeFiles() throws IOException {
		FileReader file1 = null;
		FileReader file2 = null;
		try {
			file1 = new FileReader(this.filepath1);
			file2 = new FileReader(this.filepath2);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		BufferedReader br1 = new BufferedReader(file1);
		BufferedReader br2 = new BufferedReader(file2);

		String temp1 = null, temp2 = null;
		while (br1.readLine() != null) {
			temp1 = br1.readLine() + temp1;
		}
		while (br2.readLine() != null) {
			temp2 = br2.readLine() + temp2;
		}
		String temp = temp1 + temp2;

		FileWriter fw = new FileWriter("c:\\data3.txt");
		char buffer[] = new char[temp.length()];
		temp.getChars(0, temp.length(), buffer, 0);
		fw.write(buffer);
		file1.close();
		file2.close();
		fw.close();
	}
}